package com.vf.admin.client.dao;

import cn.hutool.core.util.ObjectUtil;
import com.vf.admin.common.db.BaseDao;
import com.vf.admin.miaodong.entity.AppRoom;
import com.vf.admin.miaodong.entity.AppSms;
import com.vf.admin.miaodong.entity.AppSmsIp;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * 短信
 */
@Repository
public class AppSmsIpDao extends BaseDao<AppSmsIp> {
    public void save(AppSmsIp entity) {
        if (entity.getId() != null && entity.getId() > 0) {
            this.update(entity);
        } else {
//            List<AppSmsIp> list = getByIpAndPhone(entity.getIp(), entity.getPhone());
//            if(ObjectUtil.isNotEmpty(list)){
//                return;
//            }
            entity.setId(this.add(entity));
        }
    }

    public List<AppSmsIp> getByIp(String ip){
        if (StringEx.isNullOrLing(ip)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_sms_ip where 1=1");
        sbStr.append(" and ip = ? ");
        paramList.add(ip);
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppSmsIp.class);
    }

    public List<AppSmsIp> getByIpAndPhone(String ip, String phone){
        if (StringEx.isNullOrLing(ip) || StringEx.isNullOrLing(phone)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_sms_ip where 1=1");
        sbStr.append(" and ip = ? and phone = ?");
        paramList.add(ip);
        paramList.add(phone);
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppSmsIp.class);
    }
}
